<template>
  <div>
    <el-card>

      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="195px" class="demo-ruleForm">
        <el-row>
          <el-col :span="24">
            <p>
              伤害值配置
            </p>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工休假规则" prop="HolidayRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.HolidayRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工休假指定天规则" prop="LeisureAssignDaysRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.LeisureAssignDaysRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工休假天数规则" prop="LeisureDaysRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.LeisureDaysRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工休假部分周末规则" prop="LeisurePartialWeekendRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.LeisurePartialWeekendRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工休假整个周末规则" prop="LeisureWholeWeekendRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.LeisureWholeWeekendRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作指定天规则" prop="WorkingAssignDaysRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingAssignDaysRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作连续天数限制规则" prop="WorkingContinuousDaysRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingContinuousDaysRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作天数规则" prop="WorkingDaysRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingDaysRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作小时数限制规则" prop="WorkingHoursRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingHoursRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="最小工作时间间隔规则" prop="WorkingMinGapHoursRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingMinGapHoursRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作模式规则" prop="WorkingModeRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingModeRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作部分周末规则" prop="WorkingPartialWeekendRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingPartialWeekendRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作某班次限制规则" prop="WorkingShiftsRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingShiftsRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="员工工作整个周末规则" prop="WorkingWholeWeekendRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.WorkingWholeWeekendRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="机构营业时间限制规则" prop="BranchBusinessTimeRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.BranchBusinessTimeRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="坐席数量限制规则" prop="SeatNumRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.SeatNumRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="人力需求规则" prop="RequirementRule">
              <el-input style="width:75%;" type='text' onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" v-model="ruleForm.RequirementRule" size="small"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4" :offset="16">
            <el-button size="small" type="primary" @click="submitForm('ruleForm')">保存</el-button>
            <el-button size="small" type="danger" @click="resetForm('ruleForm')">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </el-card>

  </div>
</template>
<script>
  import request from "@/common/utils/requestWFM";
  import Query from '@/message/wfm/intelligenceSchedule/Badness/BadnessQuery';
  import Add from '@/message/wfm/intelligenceSchedule/Badness/BadnessAdd';

  export default {
    mounted() {
      this.badnessQuery()
    },
    data() {
      return {
        ruleForm: {
          HolidayRule: '',
          LeisureAssignDaysRule: '',
          LeisureDaysRule: '',
          LeisurePartialWeekendRule: '',
          LeisureWholeWeekendRule: '',
          WorkingAssignDaysRule: '',
          WorkingContinuousDaysRule: '',
          WorkingDaysRule: '',
          WorkingHoursRule: '',
          WorkingMinGapHoursRule: '1000',
          WorkingModeRule: '',
          WorkingPartialWeekendRule: '',
          WorkingShiftsRule: '',
          WorkingWholeWeekendRule: '',
          BranchBusinessTimeRule: '',
          SeatNumRule: '',
          RequirementRule: '1'
        },
        rules:{
          HolidayRule: [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          LeisureAssignDaysRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          LeisureDaysRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          LeisurePartialWeekendRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          LeisureWholeWeekendRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingAssignDaysRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingContinuousDaysRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingDaysRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingHoursRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          // WorkingMinGapHoursRule:  [
          //   { required: true, message: '请输入伤害值', trigger: 'blur' },
          //   // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          // ],
          WorkingModeRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingPartialWeekendRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingShiftsRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          WorkingWholeWeekendRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          BranchBusinessTimeRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          SeatNumRule:  [
            { required: true, message: '请输入伤害值', trigger: 'blur' },
            // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
          ],
          RequirementRule: ''
        }
      }
    },
    methods: {
       submitForm(formName) {
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            let resBody = new Add()
            resBody.data = JSON.parse(JSON.stringify(this.ruleForm))
            let response = await request(resBody);
            if (response.SYS_HEAD.ReturnCode == "000000") {
              this.$message({
                type: "success",
                message: '保存成功'
              })
              this.badnessQuery()
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
              })
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      // 伤害值查询
      async badnessQuery() {
        let resBody = new Query()
        let response = await request(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.ruleForm = response.BODY
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
    },
  }

</script>
<style lang="scss" scoped>

</style>
